import os
from PyPDF2 import PdfReader

def count_pdf_pages(folder_path):
    total_pages = 0
    pdf_files = [f for f in os.listdir(folder_path) if f.lower().endswith('.pdf')]
    pdf_page_counts = {}

    for pdf_file in pdf_files:
        file_path = os.path.join(folder_path, pdf_file)
        with open(file_path, 'rb') as file:
            pdf = PdfReader(file)
            num_pages = len(pdf.pages)
            pdf_page_counts[pdf_file] = num_pages
            total_pages += num_pages

    return pdf_page_counts, total_pages

folder_path = r'E:\postgraduate\打印文档\测试课件2024-C++'  # 修改为你的文件夹路径
pdf_page_counts, total_pages = count_pdf_pages(folder_path)

print(f"文件夹中的PDF文件页数如下：")
for pdf_file, num_pages in pdf_page_counts.items():
    print(f"{pdf_file}: {num_pages}页")

print(f"\n总页数: {total_pages}页")
